<template>
  <view>
    <u-navbar title="卡管理">
      <!-- <template #right v-if="b_cardcz">
				<view>
					<u-icon @click="gopage(`../Card/Cardadd.html?printid=${query.printid}&type=tapjh`)" color="#2093f5"
						name="qia1" custom-prefix="custom-icon" size="40"
						:customStyle="{width:'80rpx',height:'80rpx',display:'flex',justifContent:'center',alignItem:'center'}">
					</u-icon>
				</view>
			</template> -->
    </u-navbar>
    <!-- iconfont iconqia1 mui-pull-right  ng-scope -->
    <formz ref="formz" :inputs="inputs" :data="data"></formz>
    <fixedbtn>
      <u-button
        :loading="loading"
        type="error"
        @click="del"
        :custom-style="btnstyle"
      >
        删除
      </u-button>
      <u-button
        :loading="loading"
        type="primary"
        @click="confirmfn"
        :custom-style="btnstyle"
      >
        修改
      </u-button>
    </fixedbtn>
    <zmodal ref="zmodal"></zmodal>
  </view>
</template>

<script>
  import json from "../Cardsadd/cardjson.js";
  export default {
    data() {
      return {
        inputs: json.addjson.map((e) => {
          if (e.value == "printid") {
            e.disabled = true;
          }
          return e;
        }),
        data: {},
        loading: false,
        query: {},
        btnstyle: {
          padding: "8rpx 20rpx",
          fontSize: "32rpx",
          flex: "1",
          margin: "30rpx",
        },
      };
    },
    onLoad(query) {
      this.query = query;
      this.init();
    },
    computed: {
      b_cardcz() {
        return this.$store.state.upw.upw.b_cardcz == "1";
      },
    },
    methods: {
      async init() {
        // if (!this.query.cardid || !this.query.printid) {
        // 	this.$u.toast("错误")
        // 	return
        // }
        // await this.$store.dispatch("user/getUSearch");
        // await this.$store.dispatch("upw/getUpw");
        let user = this.$store.state.user.USearch;
        // await this.$store.dispatch('station/getstationfn', user.pcs)
        let Cards = await this.$z.request("/Cards", {
          cardid: this.query.cardid,
          printid: this.query.printid,
        });

        this.data = Cards[0];
      },
      gopage(url) {
        window.location.href = url;
      },
      async del() {
        this.$refs.zmodal.init({
          content: "删除此数据",
          showcancel: true,
          confirm: async () => {
            let par = await this.$z.request("/Cardsedt", {
              ...this.data,
              pcs: 1,
              type: 0,
            });
            if (par[0].par == "succeed") {
              this.$refs.zmodal.init({
                content: "操作成功",
                confirm: () => {
                  this.$z.back();
                },
              });
            }
          },
        });
      },
      async confirmfn() {
        let data = await this.$refs.formz.validate();
        if (data.yxq == "") {
          delete data.yxq;
        }
        this.loading = true;
        let par = await this.$z.request("/Cardsedt", data);
        if (par[0].par == "succeed") {
          this.$refs.zmodal.init({
            content: "操作成功",
            confirm: () => {
              this.$z.back();
            },
          });
        }
      },
    },
  };
</script>

<style lang="scss" scoped>
  .fixedbtnbox {
    width: 100%;
    padding: 0 30rpx;
  }
</style>
